require("../css/common.css")
require("../css/index.less")
require("../lib/swiper/swiper-bundle.css")
require("../lib/swiper/swiper-bundle.js")
//调用登录拦截
window.$utils.checkLogin()
document.ready(function(){
    //调用公共的footer
    window.$utils.footer(0)
    //初始化轮播
    new Swiper ('.swiper-container', {
        loop: true, // 循环模式选项
        autoplay:true,
        // 如果需要分页器
        pagination: {
          el: '.swiper-pagination',
        }
        })
    //请求首页数据
    //获取元素
    let rank=document.querySelector(".major li:nth-of-type(1) span")
    let badge=document.querySelector(".major li:nth-of-type(4) span")
    let open=document.querySelector(".major li:nth-of-type(2) span")
    let openbtn=document.querySelector(".major li:nth-of-type(2) a")

    let course=document.querySelector(".major li:nth-of-type(5)")
    let databox=document.querySelector(".major li:nth-of-type(3)")

    let idData=JSON.parse(localStorage.getItem("user"))
    let user=idData.userId
    window.$http.get(`/headPageInfo?userId=`+user,function(res){
        console.log(res);
        rank.innerHTML=res.data.rank
        badge.innerHTML=res.data.insigniaNum
        open.innerHTML=res.data.punchIn
        if(res.data.isPunch===false){
            //打卡事件
            openbtn.addEventListener("click",openbIn)
        }else{
            openbtn.textContent="今日已打卡"
            openbtn.addEventListener("click",openbIn)
        }
    })
    function openbIn(){
        window.$http.get(`/clockIn?userId=`+user,function(res){
            console.log(res);
            if(res.status==0){
                open.textContent=parseInt(open.textContent)+1
                openbtn.textContent="今日已打卡"
                window.$utils.toast(res.status,res.msg,"打卡")
            }else{
                window.$utils.toast(res.status,res.msg,"打卡")
            }
        })
    }
    course.addEventListener("click",function(){
        location.href="../course.html"
    })
    databox.addEventListener("click",function(){
        location.href="../sports_data.html"
    })

})